package com.zzyl.config;

import cn.hutool.json.JSONUtil;
import com.zzyl.service.ResourceService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.core.StringRedisTemplate;

import java.util.List;

@Slf4j
@Configuration
public class InitConfig implements InitializingBean {

    @Autowired
    private ResourceService resourceService;
    @Autowired
    private StringRedisTemplate redisTemplate;

    /**
     * 查询所有的按钮资源放入redis中
     * @throws Exception
     */
    @Override
    public void afterPropertiesSet() throws Exception {
        log.info("正在进行资源按钮路径初始化");
        List<String> allUrls =  resourceService.findAllButResource();
        redisTemplate.opsForValue().set("resource:url", JSONUtil.toJsonStr(allUrls));
    }
}
